package com.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 13. 区间交集
 * https://blog.csdn.net/wuxiao3816/article/details/107256182
 */
public class NiukeMoni15 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        List<Integer[]> list = new ArrayList<>();

        String str = scanner.nextLine();
        String[] strArr = str.split(" ");
        for (int i = 0; i < strArr.length / 2; i++) {
            Integer[] qujian = new Integer[2];
            qujian[0] = Integer.parseInt(strArr[2 * i]);
            qujian[1] = Integer.parseInt(strArr[2 * i + 1]);
            list.add(qujian);
        }

        // --------------------------------------------------------
        List<Integer[]> result = new ArrayList<>();
        for (int i = 0; i < list.size() - 1; i++) {
            Integer[] wai = list.get(i);
            for (int j = i + 1; j < list.size(); j++) {
                Integer[] li = list.get(j);
                if (!(wai[0] > li[1] || wai[1] < li[0])) { // wai 和 li 有交集
                    Integer[] jiaoJi = new Integer[2];
                    jiaoJi[0] = Math.max(wai[0], li[0]);
                    jiaoJi[1] = Math.min(wai[1], li[1]);
                    System.out.println("~~~ [" + jiaoJi[0] + ", " + jiaoJi[1] + "]");
                    if (result.size() == 0) {
                        result.add(jiaoJi);
                    } else {
                        // 得到的交集一定要添加到结果中，但如果交集和已有结果中的一些区间可以合并，算出最终的合并区间
                        // 把这些能合并的区间添加到一个临时集合中，最后都从结果中移除，只把算出的合并区间添加进去即可
                        List<Integer[]> hebing = new ArrayList<>();
                        for (int k = 0; k < result.size(); k++) {
                            Integer[] curr = result.get(k);
                            if (!(curr[0] > jiaoJi[1] || curr[1] < jiaoJi[0])) { // curr 和 jiaoJi 有交集
                                hebing.add(curr);
                                jiaoJi[0] = Math.min(jiaoJi[0], curr[0]);
                                jiaoJi[1] = Math.max(jiaoJi[1], curr[1]);
                                System.out.println("--- [" + jiaoJi[0] + ", " + jiaoJi[1] + "]");
                            }
                        }

                        result.removeAll(hebing);
                        result.add(jiaoJi);
                    }
                }
            }
        }

        if (result.size() == 0) {
            System.out.println("None");
        } else {
            for (Integer[] item : result) {
                System.out.println(Arrays.toString(item));
            }
        }
    }

}
